package com.steak.bootactivemq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;

@RestController
public class CommodityController {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    @GetMapping("/reduceStock")
    public String reduceStock(@RequestParam("commodityId")String commodityId){
        System.out.println("单号   "+commodityId);
        if (commodityId != null){
            jmsMessagingTemplate.convertAndSend(queue,commodityId);
        }
        return "下单成功";
    }


}
